using System;
using System.Collections.Generic;
using System.Text;

using Mud.Common.Messages;
using Mud.Common.Physical;
using Mud.Server.Physical;

namespace Mud.Server.Client.Commands
{

    /// <summary>
    /// Command to move the creature
    /// </summary>
    [MessageHandler(MessageTypeIds.CommandCreatureSay)]
    public class CommandCreatureSay : InstantControlerCommand
    {

        private MessageCommandCreatureSay _command;
        private Creature _creature;


        public override IMessage CanExecute()
        {
            return MessageResponseOk.Instance;
        }

        protected override IMessage StartCommandImpl()
        {
            _command = AssertIsMessage<MessageCommandCreatureSay>(CommandData);
            _creature = CommandControler.ControledCreature;
            CommunicationType type = _command.SayType;
            Creature target = null;
            if (_command.TargetCreatureId != 0)
            {

                if (!_creature.CurrentArea.Creatures.ContainsKey(_command.TargetCreatureId))
                    return new MessageResponseError("There is no such creature in the area.");

                target = _creature.CurrentArea.Creatures[_command.TargetCreatureId];
            }
            EventCreatureSay e = new EventCreatureSay(_creature, type, _command.Message, target);
            e.Send(_creature.CurrentArea);
            return MessageResponseOk.Instance;
        }

    }
}
